/*
 * @Description: websocket manager
 * @Author: Bo.LiBo@bshg.com
 * @version: H3.0
 * @Date: 2023-04-07 08:56:34
 * @LastEditTime: 2023-04-07 18:06:13
 */

import { WebsocketHandlerImp } from './WebSocketHandlerImp'
import { WebsocketUrls } from './constants'

export class WebsocketManager {
  public inhouseWebsocket: WebsocketHandlerImp
  public oemWebsocket: WebsocketHandlerImp
  public static websocketManager: WebsocketManager
  private intervalTimer: number = -1

  static get instance() {
    if (!WebsocketManager.websocketManager) {
      WebsocketManager.websocketManager = new WebsocketManager()
    }
    return WebsocketManager.websocketManager
  }

  constructor() {
    this.inhouseWebsocket = new WebsocketHandlerImp(WebsocketUrls.Inhouse)
    this.oemWebsocket = new WebsocketHandlerImp(WebsocketUrls.Oem)
  }

  public connectWebsocket() {
    setTimeout(() => {
      this.inhouseWebsocket.createConnection()
      this.oemWebsocket.createConnection()
    }, 1000)
  }

  public closeWebsocketConnection() {
    this.inhouseWebsocket.closeConnection()
    this.oemWebsocket.closeConnection()
  }
}
